//
//  BKCMTransformModel.m
//  bestkeep
//
//  Created by 毛韶谦 on 2017/1/16.
//  Copyright © 2017年 utouu. All rights reserved.
//

#import "BKCMTransformModel.h"
#import "BKCMGoodsDetailModel.h"
#import "BKSCCommon.h"

@implementation BKCMTransformModel


+ (BKCMRecommendGoodsModel *)buyCarRecommendGoodsDataDictionaryTransformModel:(id)responseObject {
    
    NSDictionary *result_dic = responseObject;
    
        NSDictionary *data_dic = [result_dic objectForKey:@"data"];
        
        NSMutableArray *list_array = [data_dic objectForKey:@"list"];
        
        BKCMRecommendGoodsModel *superSH = [[BKCMRecommendGoodsModel alloc] init];
        superSH.shopList = [[NSMutableArray alloc] init];
        superSH.currentPage = [data_dic objectForKey:@"currentPage"];//当前页数；
        superSH.totalPage = [data_dic objectForKey:@"totalPage"];//总共页数；
        for (NSDictionary *dic1 in list_array) {
            
            BKCMGoodsDetailModel* shoppingCarList = [[BKCMGoodsDetailModel alloc] init];
            shoppingCarList.good_id = [dic1 objectForKey:@"goodsId"] ;//商品id
            shoppingCarList.goods_img = [dic1 objectForKey:@"goodsCoverImg"];//商品图片
            shoppingCarList.goods_name = [dic1 objectForKey:@"goodsName"];//商品名称
            shoppingCarList.goods_price = [dic1 objectForKey:@"goodsPrice"];// 商品平台价
            shoppingCarList.status = [dic1 objectForKey:@"status"];   //商品状态1：上架，4：即将上线
            shoppingCarList.upText = [dic1 objectForKey:@"upText"];  //起字；
            shoppingCarList.channelType = [dic1 objectForKey:@"channelType"];
            shoppingCarList.goodsMarketPrice = [dic1 objectForKey:@"goodsMarketPrice"];
            
            [superSH.shopList addObject:shoppingCarList];
        }
    return superSH;
}

+ (NSMutableArray *)dictionaryTransformModel:(id)responseObject{
    
    NSDictionary *result_dic = responseObject;
    
    BOOL success = [[result_dic objectForKey:@"success"] boolValue];
    if (success) {
        
        NSDictionary *data_dic = [result_dic objectForKey:@"data"];
        
        NSMutableArray *list_array = [data_dic objectForKey:@"list"];
        
        NSMutableArray *allTemp_array = [NSMutableArray new];  //展示的所有信息集合
        
        for (NSDictionary *dic1 in list_array) {
            
            BKCMRecommendGoodsModel *superSH = [[BKCMRecommendGoodsModel alloc] init];
            superSH.shopList = [[NSMutableArray alloc] init];
            superSH.address = [dic1 objectForKey:@"deliver"];//发货地址
            superSH.global_status1 = [[dic1 objectForKey:@"global_status"] boolValue];//是否为全球购
            //                superSH.deliverId = [dic1 objectForKey:@"deliverId"];
            
            NSArray *itemArray = [dic1 objectForKey:@"item_list"];
            for (NSDictionary *dic2 in itemArray) {
                BKCMGoodsDetailModel* shoppingCarList = [[BKCMGoodsDetailModel alloc] init];
                shoppingCarList.buyEarth = superSH.global_status1;
                shoppingCarList.record_id = [dic2 objectForKey:@"id"];//购物车记录id
                shoppingCarList.good_id = [dic2 objectForKey:@"goods_id"] ;//商品id
                shoppingCarList.goods_img = [dic2 objectForKey:@"goods_img"];//商品图片
                shoppingCarList.goods_name = [dic2 objectForKey:@"goods_name"];//商品名称
                
                shoppingCarList.sendDateStr = [dic2 objectForKey:@"sendDateStr"];
                shoppingCarList.deliverId = [dic1 objectForKey:@"deliverId"];
                shoppingCarList.sendDate_param=  [dic2 objectForKey:@"sendDate_param"];                
                shoppingCarList.goods_share_amount = [dic2 objectForKey:@"goods_share_amount"];// 商品导购金
                shoppingCarList.goods_price = [dic2 objectForKey:@"goods_price"];// 商品平台价
                shoppingCarList.member_share_amount = [dic2 objectForKey:@"member_share_amount"];// 会员导购价
                
                shoppingCarList.userPrice =[dic2 objectForKey:@"userPrice"];
                shoppingCarList.member_price = [[dic2 objectForKey:@"member_price"] stringValue];//会员价
                shoppingCarList.tax_amount = [[dic2 objectForKey:@"tax_amount"] stringValue];//糖赋
                shoppingCarList.amount = [[dic2 objectForKey:@"amount"] stringValue];//商品数量
                shoppingCarList.goods_reserve_id = [dic2 objectForKey:@"goods_reserve_id"];   //库存id
                
                shoppingCarList.shopcart_flag = [[dic2 objectForKey:@"shopcart_flag"] boolValue]; //商品是否过期；
                shoppingCarList.singleDeliver = [[dic2 objectForKey:@"singleDeliver"] boolValue];//商品是否单独发货
                
                shoppingCarList.stockShareCode = [[dic2 objectForKey:@"stockShareCode"] stringValue]; //"xxx囤货分享码",
                shoppingCarList.thNormalType = [[dic2 objectForKey:@"thNormalType"] boolValue];//0/1,是否囤货普通预购，1：是，0：否", thnormalFlag
                shoppingCarList.storeId = checkNull([dic2 objectForKey:@"storeId"]);// "小店Id
                shoppingCarList.shopKeeper = checkNull([dic2 objectForKey:@"shopKeeper"]);//"小店店主账号",
                
                shoppingCarList.sale_property  =  checkNull([dic2 objectForKey:@"sale_property"]);//销售描述,例：颜色：黑色，尺码：S
                shoppingCarList.signCustomsAmount = [dic2 objectForKey:@"linePost_taxAmount"]; //海关税
                [superSH.shopList addObject:shoppingCarList];//存储所有商品信息
            }
            [allTemp_array addObject:superSH];
        }
        return allTemp_array;
    }
    
    return nil;
}
@end
